package com.lmscn.lms.api.model;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

import java.util.List;

/**
 * Created by Czl on 2015/8/4.
 */
@SuppressWarnings("serial")
public class ClazzStudent extends Model<ClazzStudent> {

    public static final ClazzStudent dao = new ClazzStudent();

    /**
     * 查询所在班级
     * @param studentId
     * @return
     */
    public List<ClazzStudent> findByStudentId(Long studentId){
        return dao.find("select * from t_clazz_student where student_id = ?",studentId);
    }

    /**
     * 查询班级人数
     * @param clazzId
     * @return
     */
    public Long findStudentNum(Long clazzId){
        return Db.queryLong("select count(student_id) from t_clazz_student where class_id = ?", clazzId);
    }

    /**
     * 分页查询班级通讯录
     * @param pageNumber
     * @param pageSize
     * @param classId
     * @return
     */
    public Page<ClazzStudent> findClazzStudentPage(int pageNumber,int pageSize,Long classId){
        return dao.paginate(pageNumber,pageSize,"select t.* "," from t_clazz_student t where t.class_id = ?",classId);
    }

    /**
     * 根据studentId，clazzId
     * 查询班级学员关系表
     * @param studentId
     * @param clazzId
     * @return
     */
    public ClazzStudent findByClazzIdAndStuId(Long studentId,Long clazzId){
        return dao.findFirst("select * from t_clazz_student where class_id = ? and student_id = ?",clazzId,studentId);
    }
}
